/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package invento;


import java.util.logging.Level;
import javax.swing.*;
import java.sql.Connection;
import java.sql.*;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Logger;


/**
 *
 * @author Kristina
 * @editor Daryl
 */
public class DbConnector {
    public Statement statement;
    public Connection conn;

    //public Welcome welcome = new Welcome();
    private JTable archiveFirearm = new JTable();
    private JTable archiveEquip = new JTable();
    private JTable archiveVehicle = new JTable();

    private String sTemp;
    private int rowCount;
    private int colCount;
    private int rowArchive;

    public void dbConnect()
    {
        conn = null;
        String url = "jdbc:mysql://localhost:3306/";
        String dbName = "inventorysystem";
        String driverName = "com.mysql.jdbc.Driver";
        String userName = "root";
        String password = "root";
        
        try {
        Class.forName(driverName).newInstance();
        conn = DriverManager.getConnection(url+dbName, userName, password);
        statement = conn.createStatement();
        
        }
        catch (Exception e){
            e.printStackTrace();
        }
    }

    public void refreshDisplay(JTable jTable1, JTable jTable2, JTable jTable3, JTable jTable4)
    {
        displayFirearm(jTable1);
        displayVehicle(jTable2);
        displayEquipment(jTable3);
        displayPersonnel(jTable4);
    };

    public String retrieveAdminName()
    {   ResultSet rSet;

        try{
            rSet = statement.executeQuery("SELECT Username FROM inventorysystem.profile WHERE Type = 'Administrator'");
            
            while(rSet.next())
            {
                sTemp = rSet.getString("Username");
            }
        }
        catch (Exception e){
            e.printStackTrace();
        }
        
        return sTemp;
    };

    public String retrieveUserName()
    {
        ResultSet rSet;

        try{
            rSet = statement.executeQuery("SELECT Username FROM inventorysystem.profile WHERE Type = 'User'");
            while(rSet.next())
            {
                sTemp = rSet.getString("Username");
            }
        }
        catch (Exception e){
            e.printStackTrace();
        }

        return sTemp;
    };

    public String retrieveAdminPass()
    {
        ResultSet rSet;

        try{
            rSet = statement.executeQuery("SELECT Password FROM inventorysystem.profile WHERE Type = 'Administrator'");
            while(rSet.next())
            {
                sTemp = rSet.getString("Password");
            }
        }
        catch (Exception e){
            e.printStackTrace();
        }
       
        return sTemp;
    };

    public String retrieveUserPass()
    {
        ResultSet rSet;

        try{
            rSet = statement.executeQuery("SELECT Password FROM inventorysystem.profile WHERE Type = 'User'");
            while(rSet.next())
            {
                sTemp = rSet.getString("Password");
            }
        }
        catch (Exception e){
            e.printStackTrace();
        }

        return sTemp;
    };

    public String retrievePassword(String userType)
    {
        ResultSet rSet;

        try{
            rSet = statement.executeQuery("SELECT Password FROM inventorysystem.profile WHERE Type = '"+ userType +"'");
            while(rSet.next())
            {
                sTemp = rSet.getString("Password");
            }
        }
        catch (Exception e){
            e.printStackTrace();
        }
        return sTemp;
    };

    public String retrieveHint(String user)
    {
        ResultSet rSet;

        try{
            rSet = statement.executeQuery("SELECT Hint FROM inventorysystem.profile WHERE Username = '"+user+"'");
            while(rSet.next())
            {
                sTemp = rSet.getString(1);
            }
        }
        catch (Exception e){
            e.printStackTrace();
        }

        
        return sTemp;
    };


    public void displayFirearm(JTable jTable1)
    {
        int row = 0;
        ResultSet rSet;
        
        
        
        try {
            rSet = statement.executeQuery("SELECT * FROM inventorysystem.firearm");
            
           
            while(rSet.next()){
                
           String PropNo = rSet.getString("PropertyNo");
 	   String Categ = rSet.getString("Category");
           String Stat = rSet.getString("Status");
           String Type = rSet.getString("Type");
           String Make = rSet.getString("Make");
           String Calib = rSet.getString("Calibre");
           String SerNo = rSet.getString("SerialNo");
           String AcqDate = rSet.getString("AcquisitionDate");
 	   String AcqCost = rSet.getString("AcquisitionCost");
           String RepCost = rSet.getString("RepairCost");
           String Source = rSet.getString("Source");

           jTable1.setValueAt(PropNo, row, 0);
           jTable1.setValueAt(Categ, row, 1);
           jTable1.setValueAt(Stat, row, 2);
           jTable1.setValueAt(Type, row, 3);
           jTable1.setValueAt(Make, row, 4);
           jTable1.setValueAt(Calib, row, 5);
           jTable1.setValueAt(SerNo, row, 6);
           jTable1.setValueAt(AcqDate, row, 7);
           jTable1.setValueAt(AcqCost, row, 8);
           jTable1.setValueAt(RepCost, row, 9);
           jTable1.setValueAt(Source, row, 10);

           row++;
           }
        }
        catch (Exception e){
            e.printStackTrace();
        }
    }

    public void displayVehicle(JTable jTable2)
    {
        int row = 0;
        ResultSet rSet;

        try{
            rSet = statement.executeQuery("SELECT * FROM inventorysystem.vehicle");

        while(rSet.next()){

           String PropNo = rSet.getString("PropertyNo");
 	   String Stat = rSet.getString("Status");
           String Type = rSet.getString("Type");
           String Make = rSet.getString("Make");
           String EngNo = rSet.getString("EngineNo");
           String ChasNo = rSet.getString("ChassisNo");
           String PlateNo = rSet.getString("PlateNo");
           String AcqDate = rSet.getString("AcquisitionDate");
 	   String AcqCost = rSet.getString("AcquisitionCost");
           String RepCost = rSet.getString("RepairCost");
           String Source = rSet.getString("Source");

           jTable2.setValueAt(PropNo, row, 0);
           jTable2.setValueAt(Stat, row, 1);
           jTable2.setValueAt(Type, row, 2);
           jTable2.setValueAt(Make, row, 3);
           jTable2.setValueAt(EngNo, row, 4);
           jTable2.setValueAt(ChasNo, row, 5);
           jTable2.setValueAt(PlateNo, row, 6);
           jTable2.setValueAt(AcqDate, row, 7);
           jTable2.setValueAt(AcqCost, row, 8);
           jTable2.setValueAt(RepCost, row, 9);
           jTable2.setValueAt(Source, row, 10);

           row++;
            }
        }
        catch (Exception e){
            e.printStackTrace();
        }
}

    public void displayEquipment(JTable jTable3)
    {
        int row = 0;
        ResultSet rSet;

        try{
            rSet = statement.executeQuery("SELECT * FROM inventorysystem.equipment");

        while(rSet.next()){

           String PropNo = rSet.getString("PropertyNo");
 	   String Stat = rSet.getString("Status");
           String Type = rSet.getString("Type");
           String SerNo = rSet.getString("SerialNo");
           String AcqDate = rSet.getString("AcquisitionDate");
 	   String AcqCost = rSet.getString("AcquisitionCost");
           String RepCost = rSet.getString("RepairCost");
           String Source = rSet.getString("Source");

           jTable3.setValueAt(PropNo, row, 0);
           jTable3.setValueAt(Stat, row, 1);
           jTable3.setValueAt(Type, row, 2);
           jTable3.setValueAt(SerNo, row, 3);
           jTable3.setValueAt(AcqDate, row, 4);
           jTable3.setValueAt(AcqCost, row, 5);
           jTable3.setValueAt(RepCost, row, 6);
           jTable3.setValueAt(Source, row, 7);

           row++;
            }
        }
        catch (Exception e){
            e.printStackTrace();
        }
    }

    public void displayPersonnel(JTable jTable4)
    {
        int row = 0;
        ResultSet rSet;

        try{
            rSet = statement.executeQuery("SELECT * FROM inventorysystem.personnel");

        while(rSet.next()){

           String badgeNo = rSet.getString("BadgeNo");
 	   String unit = rSet.getString("Unit");
           String bata = rSet.getString("Battalion");
           String comp = rSet.getString("Company");
           String rank = rSet.getString("Rank");
           String nLast = rSet.getString("LastName");
           String nFirst = rSet.getString("FirstName");
           String nMid = rSet.getString("MiddleName");
 	   String quali = rSet.getString("Qualifier");
           String uCode = rSet.getString("UnitCode");
          
           jTable4.setValueAt(badgeNo, row, 0);
           jTable4.setValueAt(unit, row, 1);
           jTable4.setValueAt(bata, row, 2);
           jTable4.setValueAt(comp, row, 3);
           jTable4.setValueAt(rank, row, 4);
           jTable4.setValueAt(nLast, row, 5);
           jTable4.setValueAt(nFirst, row, 6);
           jTable4.setValueAt(nMid, row, 7);
           jTable4.setValueAt(quali, row, 8);
           jTable4.setValueAt(uCode, row, 9);

           row++;
            }
        }
        catch (Exception e){
            e.printStackTrace();
        }
    }

    public void sortFirearm(JTable table, String input)
    {
        int rowPrint = 0;
        int colPrint = 0;
        int rowCount = table.getRowCount() -1;
        int colCount = table.getColumnCount();

        ResultSet rSet;

        try{

            rSet = statement.executeQuery("SELECT * FROM inventorysystem.firearm WHERE PropertyNo LIKE '"+input+"%'");

            while(rSet.next()){

           String PropNo = rSet.getString("PropertyNo");
 	   String Categ = rSet.getString("Category");
           String Stat = rSet.getString("Status");
           String Type = rSet.getString("Type");
           String Make = rSet.getString("Make");
           String Calib = rSet.getString("Calibre");
           String SerNo = rSet.getString("SerialNo");
           String AcqDate = rSet.getString("AcquisitionDate");
 	   String AcqCost = rSet.getString("AcquisitionCost");
           String RepCost = rSet.getString("RepairCost");
           String Source = rSet.getString("Source");

           table.setValueAt(PropNo, rowPrint, 0);
           table.setValueAt(Categ, rowPrint, 1);
           table.setValueAt(Stat, rowPrint, 2);
           table.setValueAt(Type, rowPrint, 3);
           table.setValueAt(Make, rowPrint, 4);
           table.setValueAt(Calib, rowPrint, 5);
           table.setValueAt(SerNo, rowPrint, 6);
           table.setValueAt(AcqDate, rowPrint, 7);
           table.setValueAt(AcqCost, rowPrint, 8);
           table.setValueAt(RepCost, rowPrint, 9);
           table.setValueAt(Source, rowPrint, 10);

           rowPrint++;
            }
        }
        catch (Exception e){
            e.printStackTrace();
        }
    }

    public void sortVehicle(JTable table, String input)
    {
        int rowPrint = 0;
        int colPrint = 0;
        int rowCount = table.getRowCount() -1;
        int colCount = table.getColumnCount();

        ResultSet rSet;

        try{

            rSet = statement.executeQuery("SELECT * FROM inventorysystem.vehicle WHERE PropertyNo LIKE '"+input+"%'");

            while(rSet.next()){

           String PropNo = rSet.getString("PropertyNo");
 	   String Stat = rSet.getString("Status");
           String Type = rSet.getString("Type");
           String Make = rSet.getString("Make");
           String EngNo = rSet.getString("EngineNo");
           String ChasNo = rSet.getString("ChassisNo");
           String PlateNo = rSet.getString("PlateNo");
           String AcqDate = rSet.getString("AcquisitionDate");
 	   String AcqCost = rSet.getString("AcquisitionCost");
           String RepCost = rSet.getString("RepairCost");
           String Source = rSet.getString("Source");

           table.setValueAt(PropNo, rowPrint, 0);
           table.setValueAt(Stat, rowPrint, 1);
           table.setValueAt(Type, rowPrint, 2);
           table.setValueAt(Make, rowPrint, 3);
           table.setValueAt(EngNo, rowPrint, 4);
           table.setValueAt(ChasNo, rowPrint, 5);
           table.setValueAt(PlateNo, rowPrint, 6);
           table.setValueAt(AcqDate, rowPrint, 7);
           table.setValueAt(AcqCost, rowPrint, 8);
           table.setValueAt(RepCost, rowPrint, 9);
           table.setValueAt(Source, rowPrint, 10);

           rowPrint++;
            }
        }
        catch (Exception e){
            e.printStackTrace();
        }
    }
    public void sortEquipment(JTable table, String input)
    {
        int rowPrint = 0;
        int colPrint = 0;
        int rowCount = table.getRowCount() -1;
        int colCount = table.getColumnCount();

        ResultSet rSet;

        try{

            rSet = statement.executeQuery("SELECT * FROM inventorysystem.equipment WHERE PropertyNo LIKE '"+input+"%'");

            while(rSet.next()){

           String PropNo = rSet.getString("PropertyNo");
 	   String Stat = rSet.getString("Status");
           String Type = rSet.getString("Type");
           String SerNo = rSet.getString("SerialNo");
           String AcqDate = rSet.getString("AcquisitionDate");
 	   String AcqCost = rSet.getString("AcquisitionCost");
           String RepCost = rSet.getString("RepairCost");
           String Source = rSet.getString("Source");

           table.setValueAt(PropNo, rowPrint, 0);
           table.setValueAt(Stat, rowPrint, 1);
           table.setValueAt(Type, rowPrint, 2);
           table.setValueAt(SerNo, rowPrint, 3);
           table.setValueAt(AcqDate, rowPrint, 4);
           table.setValueAt(AcqCost, rowPrint, 5);
           table.setValueAt(RepCost, rowPrint, 6);
           table.setValueAt(Source, rowPrint, 7);

           rowPrint++;
            }
        }
        catch (Exception e){
            e.printStackTrace();
        }
    }
    public void sortPersonnel(JTable table, String input)
    {
        int rowPrint = 0;
        int colPrint = 0;
        int rowCount = table.getRowCount() -1;
        int colCount = table.getColumnCount();

        ResultSet rSet;

        try{

            rSet = statement.executeQuery("SELECT * FROM inventorysystem.personnel WHERE (LastName LIKE '"+input+"%') || (FirstName LIKE '"+input+"%') || (BadgeNo LIKE '"+input+"%');");

            while(rSet.next()){

           String badgeNo = rSet.getString("BadgeNo");
 	   String unit = rSet.getString("Unit");
           String bata = rSet.getString("Battalion");
           String comp = rSet.getString("Company");
           String rank = rSet.getString("Rank");
           String nLast = rSet.getString("LastName");
           String nFirst = rSet.getString("FirstName");
           String nMid = rSet.getString("MiddleName");
 	   String quali = rSet.getString("Qualifier");
           String uCode = rSet.getString("UnitCode");
          
           table.setValueAt(badgeNo, rowPrint, 0);
           table.setValueAt(unit, rowPrint, 1);
           table.setValueAt(bata, rowPrint, 2);
           table.setValueAt(comp, rowPrint, 3);
           table.setValueAt(rank, rowPrint, 4);
           table.setValueAt(nLast, rowPrint, 5);
           table.setValueAt(nFirst, rowPrint, 6);
           table.setValueAt(nMid, rowPrint, 7);
           table.setValueAt(quali, rowPrint, 8);
           table.setValueAt(uCode, rowPrint, 9);

           rowPrint++;
            }
        }
        catch (Exception e){
            e.printStackTrace();
        }
    }

    public void getPropertyNumbers()// ISSUE PROPERTIES
    {}

    public void getBadgeNumbers()// ISSUE PROPERTIES
    {}


    public void addFirearmToDatabase(String Categ, String  Stat, String  Type, String  Make, String  Calib, String  SerNo, String  PropNo, String  AcqDate, String AcqCost, String RepCost, String Source)
    {
        int intTemp = 0;

        try {   intTemp = statement.executeUpdate("INSERT INTO inventorysystem.firearm (Category, Status, Type, Make, Calibre, SerialNo, PropertyNo, AcquisitionDate, AcquisitionCost, RepairCost, Source) VALUES ("
                    + Categ + Stat + Type + Make + Calib + SerNo + PropNo + AcqDate + AcqCost + RepCost + Source);


        System.out.println("Rifle Added to Database.");
        }
        catch (Exception e) {
            e.printStackTrace();
        }

        //finally{
            try{
                statement.close();
                conn.close();
            } catch(Exception e){
                e.printStackTrace();
            }

        //}
        propUpdated();
    }

    public void addVehicleToDatabase(String  Stat, String  Type, String  Make, String  EngNo, String  ChasNo, String  PropNo, String  AcqDate, String AcqCost, String RepCost, String Source, String PlateNo)
    {
        int intTemp = 0;

        try {   intTemp = statement.executeUpdate("INSERT INTO inventorysystem.vehicle (Status, Type, Make, EngineNo, ChassisNo, PropertyNo, AcquisitionDate, AcquisitionCost, RepairCost, Source, PlateNo) VALUES ("
                    + Stat + Type + Make + EngNo + ChasNo + PropNo + AcqDate + AcqCost + RepCost + Source + PlateNo);


        System.out.println("Vehicle Added to Database.");
        }
        catch (Exception e) {
            e.printStackTrace();
        }

        finally{
            try{
                statement.close();
                conn.close();
            } catch(Exception e){
                e.printStackTrace();
            }

        }
        propUpdated();
 }

    
    public void addEquipmentToDatabase(String  Stat, String  Type, String  SerNo, String  PropNo, String  AcqDate, String AcqCost, String RepCost, String Source)
    {
        int intTemp = 0;

        try {   intTemp = statement.executeUpdate("INSERT INTO inventorysystem.equipment (Status, Type, SerialNo, PropertyNo, AcquisitionDate, AcquisitionCost, RepairCost, Source) VALUES ("
                    + Stat + Type + SerNo + PropNo + AcqDate + AcqCost + RepCost + Source);


        System.out.println("Equipment Added to Database.");
        }
        catch (Exception e) {
            e.printStackTrace();
        }

        finally{
            try{
                statement.close();
                conn.close();
            } catch(Exception e){
                e.printStackTrace();
            }

        }
        propUpdated();
    }
    


     public void addPersonnelToDatabase(String Unit, String Bata, String Comp, String Rank, String BadNo, String nLast, String nFirst, String nMid, String nQuali, String uCode)
    {
        int intTemp = 0;

        try {   intTemp = statement.executeUpdate("INSERT INTO inventorysystem.personnel (Unit, Battalion, Company, Rank, BadgeNo, FirstName, LastName, MiddleName, Qualifier, UnitCode) VALUES ("
                    + Unit + Bata + Comp + Rank + BadNo + nLast + nFirst + nMid + nQuali + uCode);

        System.out.println("Personnel Added to Database.");
        }
        catch (Exception e) {
            e.printStackTrace();
        }

        finally{
            try{
                statement.close();
                conn.close();
            } catch(Exception e){
                e.printStackTrace();
            }

        }
        persUpdated();
    }

    public void firearmToArchive(JTable tab, int rowPrint)
    {
        int intTemp;

        String PropNo = "\""+tab.getValueAt(rowPrint, 0).toString()+"\", ";
        String Categ = "\""+tab.getValueAt(rowPrint, 1).toString()+"\", ";
        String Stat = "\""+tab.getValueAt(rowPrint, 2).toString()+"\", ";
        String Type = "\""+tab.getValueAt(rowPrint, 3).toString()+"\", ";
        String Make = "\""+tab.getValueAt(rowPrint, 4).toString()+"\", ";
        String Calib = "\""+tab.getValueAt(rowPrint, 5).toString()+"\", ";
        String SerNo = "\""+tab.getValueAt(rowPrint, 6).toString()+"\", ";
        String AcqDate = "\""+tab.getValueAt(rowPrint, 7).toString()+"\", ";
        String AcqCost = "\""+tab.getValueAt(rowPrint, 8).toString()+"\", ";
        String RepCost = "\""+tab.getValueAt(rowPrint, 9).toString()+"\", ";
        String Source = "\""+tab.getValueAt(rowPrint, 10).toString()+"\");";

        try {   intTemp = statement.executeUpdate("INSERT INTO inventorysystem.firearmarchive (Category, Status, Type, Make, Calibre, SerialNo, PropertyNo, AcquisitionDate, AcquisitionCost, RepairCost, Source) VALUES ("
                    + Categ + Stat + Type + Make + Calib + SerNo + PropNo + AcqDate + AcqCost + RepCost + Source);
            }
        catch(Exception e)
            {   e.printStackTrace();
            }
        finally
            {   try{    statement.close();
                        conn.close();
                }
                catch(Exception e){
                    e.printStackTrace();
                }

            }
    }


    public void vehicleToArchive(JTable tab, int rowPrint)
    {
        int intTemp;

        String PropNo = "\""+tab.getValueAt(rowPrint, 0).toString()+"\", ";
        String Stat = "\""+tab.getValueAt(rowPrint, 1).toString()+"\", ";
 	String Type = "\""+tab.getValueAt(rowPrint, 2).toString()+"\", ";
 	String Make = "\""+tab.getValueAt(rowPrint, 3).toString()+"\", ";
        String EngNo = "\""+tab.getValueAt(rowPrint, 4).toString()+"\", ";
        String ChasNo = "\""+tab.getValueAt(rowPrint, 5).toString()+"\", ";
        String PlateNo = "\""+tab.getValueAt(rowPrint, 6).toString()+"\")";
 	String AcqDate = "\""+tab.getValueAt(rowPrint, 7).toString()+"\", ";
 	String AcqCost = "\""+tab.getValueAt(rowPrint, 8).toString()+"\", ";
        String RepCost = "\""+tab.getValueAt(rowPrint, 9).toString()+"\", ";
        String Source = "\""+tab.getValueAt(rowPrint, 10).toString()+"\", ";

        try {   intTemp = statement.executeUpdate("INSERT INTO inventorysystem.vehicle (Status, Type, Make, EngineNo, ChassisNo, PropertyNo, AcquisitionDate, AcquisitionCost, RepairCost, Source, PlateNo) VALUES ("
                    + Stat + Type + Make + EngNo + ChasNo + PropNo + AcqDate + AcqCost + RepCost + Source + PlateNo);
        }
        catch(Exception e){
            e.printStackTrace();
        }

        finally
            {   try{    statement.close();
                        conn.close();
                }
                catch(Exception e){
                    e.printStackTrace();
                }

            }
    }



    public void equipmentToArchive(JTable tab, int rowPrint)
    {
        int intTemp;

        String PropNo = "\""+tab.getValueAt(rowPrint, 0).toString()+"\", ";
        String Stat = "\""+tab.getValueAt(rowPrint, 1).toString()+"\", ";
 	String Type = "\""+tab.getValueAt(rowPrint, 2).toString()+"\", ";
 	String SerNo = "\""+tab.getValueAt(rowPrint, 3).toString()+"\", ";
 	String AcqDate = "\""+tab.getValueAt(rowPrint, 4).toString()+"\", ";
 	String AcqCost = "\""+tab.getValueAt(rowPrint, 5).toString()+"\", ";
        String RepCost = "\""+tab.getValueAt(rowPrint, 6).toString()+"\", ";
        String Source = "\""+tab.getValueAt(rowPrint, 7).toString()+"\")";


        try {   intTemp = statement.executeUpdate("INSERT INTO inventorysystem.equipmentarchive (Status, Type, SerialNo, PropertyNo, AcquisitionDate, AcquisitionCost, RepairCost, Source) VALUES ("
                    + Stat + Type + SerNo + PropNo + AcqDate + AcqCost + RepCost + Source);
            }
        catch(Exception e){
            e.printStackTrace();
        }

        finally
            {   try{    statement.close();
                        conn.close();
                }
                catch(Exception e){
                    e.printStackTrace();
                }
            }
    }




    public void updateFirearmInDatabase(String PropNo, String Categ, String Stat, String Type, String Make, String Calib, String SerNo, String AcqDate, String AcqCost, String RepCost, String Source)
    {
        int intTemp = 0;

        try {   intTemp = statement.executeUpdate("UPDATE inventorysystem.firearm SET Category = '"+Categ+"', Status = '"+Stat+"', Type = '"+Type+"', Make = '"+Make
                +"', Calibre = '"+Calib+"', SerialNo = '"+SerNo+"', AcquisitionDate = '"+AcqDate+"', AcquisitionCost = '"+AcqCost+"', RepairCost = '"+RepCost
                +"', Source = '"+Source+"' WHERE PropertyNo = '"+PropNo+"';");
            }
        catch (Exception e) {
            e.printStackTrace();
        }
        propUpdated();
    };

    public void updateVehicleInDatabase(String PropNo, String Stat, String Type, String Make, String EngNo, String ChasNo, String AcqDate, String AcqCost, String RepCost, String Source, String PlateNo)
    {
        int intTemp = 0;

        try {   intTemp = statement.executeUpdate("UPDATE inventorysystem.vehicle SET Status = '"+Stat+"', Type = '"+Type+"', Make = '"+Make+"', EngineNo = '"+EngNo
                +"', ChassisNo = '"+ChasNo+"', AcquisitionDate = '"+AcqDate+"', AcquisitionCost = '"+AcqCost+"', RepairCost = '"+RepCost+"', Source = '"+Source+"', PlateNo = '"+PlateNo
                +"' WHERE PropertyNo = '"+PropNo+"';");
            }
        catch (Exception e) {
            e.printStackTrace();
        }
        propUpdated();
    };

    public void updateSpecialInDatabase(String PropNo, String  Stat, String Type, String SerNo, String AcqDate, String AcqCost, String RepCost, String Source)
    {
        int intTemp = 0;

        try {   intTemp = statement.executeUpdate("UPDATE inventorysystem.equipment SET Status = '"+Stat+"', Type = '"+Type+"', SerialNo = '"+SerNo
                +"', AcquisitionDate = '"+AcqDate+"', AcquisitionCost = '"+AcqCost+"', RepairCost = '"+RepCost+"', Source = '"+Source
                +"' WHERE PropertyNo = '"+PropNo+"';");
            }
        catch (Exception e) {
            e.printStackTrace();
        }
        propUpdated();
    }

    public void updatePersonnelInDatabase(String BadgeNo, String Unit, String Bata, String Comp, String Rank, String nLast, String nFirst, String nMid, String Quali, String uCode)
    {
        int intTemp = 0;

        try {   intTemp = statement.executeUpdate("UPDATE inventorysystem.personnel SET Unit = '"+Unit+"', Battalion = '"+Bata+"', Company = '"+Comp+"', Rank = '"+Rank
                +"', LastName = '"+nLast+"', FirstName = '"+nFirst+"', MiddleName = '"+nMid+"', Qualifier = '"+Quali+"', UnitCode = '"+uCode
                +"' WHERE BadgeNo = '"+BadgeNo+"';");
            }
        catch (Exception e) {
            e.printStackTrace();
        }
        persUpdated();
    }

    public void updateProfile(String userType, String userName, String newPass, String hint)
    {
         int intTemp = 0;

        try {   intTemp = statement.executeUpdate("UPDATE inventorysystem.profile SET Username = '"+userName+"', Password = '"+newPass+"' WHERE Type = '"+userType+"';");
                if (hint.length() > 0)
                    intTemp = statement.executeUpdate("UPDATE inventorysystem.profile SET Hint = '"+ hint +"' WHERE Type = '"+userType+"';");
                else
                    intTemp = statement.executeUpdate("UPDATE inventorysystem.profile SET Hint = 'Hint Unavailable.' WHERE Type = '"+userType+"';");
            }
        catch (Exception e) {
            e.printStackTrace();
        }
        profUpdated();
    };

    public void addFirearmToArchives(JTable table, int row)
    {
/*
        ResultSet rSet;
        boolean isUnique = true;
        int rowPrint = row;
        JTable tab = table;

        String strPrimary = table.getValueAt(rowPrint, 0).toString();
        String strCompare;
        
        int intTemp = 0;

        try
        {
        rSet = statement.executeQuery("SELECT PropertyNo FROM inventorysystem.firearmarchive");
        System.out.println(rSet.next());
            if (!rSet.next())
            {
                firearmToArchive(tab, rowPrint);
                System.out.println("FIRST ITEM ADDED!");
            }
            else
            {   while(rSet.next())
                {   
                    String aPropNo = rSet.getString("PropertyNo");
                    archiveFirearm.setValueAt(aPropNo, rowArchive, 0);
                    rowArchive++;
                } 
                do
                {
                    strCompare = archiveFirearm.getValueAt(rowArchive, 0).toString();
                    if (strPrimary.compareTo(strCompare) == 0)
                        isUnique = false;
                    else
                        isUnique = true;

                    rowArchive++;
                } while(rowArchive < archiveFirearm.getRowCount()+1 || isUnique == true);

                if (isUnique == true)
                {
                    String PropNo = "\""+tab.getValueAt(rowPrint, 0).toString()+"\", ";
                    String Categ = "\""+tab.getValueAt(rowPrint, 1).toString()+"\", ";
                    String Stat = "\""+tab.getValueAt(rowPrint, 2).toString()+"\", ";
                    String Type = "\""+tab.getValueAt(rowPrint, 3).toString()+"\", ";
                    String Make = "\""+tab.getValueAt(rowPrint, 4).toString()+"\", ";
                    String Calib = "\""+tab.getValueAt(rowPrint, 5).toString()+"\", ";
                    String SerNo = "\""+tab.getValueAt(rowPrint, 6).toString()+"\", ";
                    String AcqDate = "\""+tab.getValueAt(rowPrint, 7).toString()+"\", ";
                    String AcqCost = "\""+tab.getValueAt(rowPrint, 8).toString()+"\", ";
                    String RepCost = "\""+tab.getValueAt(rowPrint, 9).toString()+"\", ";
                    String Source = "\""+tab.getValueAt(rowPrint, 10).toString()+"\");";

                    try {
                        intTemp = statement.executeUpdate("INSERT INTO inventorysystem.firearmarchive (Category, Status, Type, Make, Calibre, SerialNo, PropertyNo, AcquisitionDate, AcquisitionCost, RepairCost, Source) VALUES ("
                            + Categ + Stat + Type + Make + Calib + SerNo + PropNo + AcqDate + AcqCost + RepCost + Source);
                        }
                    catch(Exception e)
                    {
                        e.printStackTrace();
                    }
                }
            }

                statement.close();
                dbConnect();

                rSet = statement.executeQuery("SELECT PropertyNo FROM inventorysystem.firearmarchive");
                System.out.println(rSet.next());
                while(rSet.next())
                {
                    
                        String aPropNo = rSet.getString("PropertyNo");
                        System.out.println(rSet.getRow());
                        System.out.println(rowPrint);
                        System.out.println(rowArchive);


                    archiveFirearm.setValueAt(aPropNo, 1, 0);
                    rowArchive++;
                }
                
                System.out.println(rowArchive+" TANGINA");
                System.out.println(rowPrint+"~");
                System.out.println(rowArchive+"~");


        }
        catch(Exception e)
        {
            e.printStackTrace();
        } */
    }

    public void addVehicleToArchives(JTable tab)
    {}

    public void addEquipmentToArchives(JTable tab)
    {}















    public void viewFirearmArchives(JTable table1)
    {
        /*int row = 0;
        ResultSet rSet;
        
        try {
            rSet = statement.executeQuery("SELECT * FROM inventorysystem.firearmarchive");
            
            while(rSet.next()){

           String Categ = rSet.getString("Category");
           String Stat = rSet.getString("Status");
           String Type = rSet.getString("Type");
           String Make = rSet.getString("Make");
           String Calib = rSet.getString("Calibre");
           String SerNo = rSet.getString("SerialNo");
           String PropNo = rSet.getString("PropertyNo");
           String AcqDate = rSet.getString("AcquisitionDate");
 	   String AcqCost = rSet.getString("AcquisitionCost");
           String RepCost = rSet.getString("RepairCost");
           String Source = rSet.getString("Source");

           table1.setValueAt(Categ, row, 1);
           table1.setValueAt(Stat, row, 2);
           table1.setValueAt(Type, row, 3);
           table1.setValueAt(Make, row, 4);
           table1.setValueAt(Calib, row, 5);
           table1.setValueAt(SerNo, row, 6);
           table1.setValueAt(PropNo, row, 0);
           table1.setValueAt(AcqDate, row, 7);
           table1.setValueAt(AcqCost, row, 8);
           table1.setValueAt(RepCost, row, 9);
           table1.setValueAt(Source, row, 10);

           row++;
            }
        }
        catch (Exception e){
            e.printStackTrace();
        }*/
    }

    public void viewEquipmentArchives(JTable table2)
    {
    }

    public void viewVehicleArchives()
    {
    }


    public void propUpdated()
    {
        System.out.println("Property Updated.");
        JOptionPane.showMessageDialog(null, "Property Has Been Recently Updated",
        "Property Update", JOptionPane.INFORMATION_MESSAGE);
    }

    public void persUpdated()
    {
        System.out.println("Personnel Updated.");
        JOptionPane.showMessageDialog(null, "Personnel Has Been Recently Updated",
        "Personnel Update", JOptionPane.INFORMATION_MESSAGE);
    }


    public void profUpdated()
    {
        System.out.println("Profile Updated.");
        JOptionPane.showMessageDialog(null, "Profile Has Been Recently Updated",
        "Profile Update", JOptionPane.INFORMATION_MESSAGE);
    }
}
